package com.jk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.dao.TbTeacherMapper;
import com.jk.dto.TbAdmin;
import com.jk.dto.TbTeacher;
import com.jk.pojo.PagedResponse;
import com.jk.service.TbTeacherService;
import com.jk.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author yzf
 * @version 1.0
 * @description: TODO
 * @date 2024/12/11 10:54
 */
@Service
public class TbTeacherServiceImpl implements TbTeacherService {
    @Autowired
    private TbTeacherMapper tbTeacherMapper;
    @Override
    public PagedResponse<TbTeacher> findTeacherList(TbTeacher tbTeacher, Integer pageNum, Integer pageSize) {
        Page<TbTeacher> page = new Page<>(pageNum, pageSize);
        QueryWrapper<TbTeacher> queryWrapper = new QueryWrapper<>();
        if (null != tbTeacher.getUserName() && !"".equals(tbTeacher.getUserName())) {
            queryWrapper.like("user_name", tbTeacher.getUserName());
        }
        Page<TbTeacher> tbTeacherPage = tbTeacherMapper.selectPage(page, queryWrapper);
        return PaginationUtil.getPagedResponse(tbTeacherPage.getRecords(),pageNum,pageSize,tbTeacherPage.getTotal());
    }

    @Override
    public void delTeacherById(Integer id) {
        tbTeacherMapper.deleteById(id);
    }

    @Override
    public void addTeacher(TbTeacher tbTeacher) {
        tbTeacher.setCreateTime(new Date());
        tbTeacherMapper.insert(tbTeacher);
    }

    @Override
    public TbTeacher getTeacherById(Integer id) {
        return tbTeacherMapper.selectById(id);
    }

    @Override
    public void upTeacher(TbTeacher tbTeacher) {
        tbTeacherMapper.updateById(tbTeacher);
    }

    @Override
    public void upstatus(TbTeacher tbTeacher) {
        tbTeacherMapper.upstatus(tbTeacher);
    }

    @Override
    public void updatestatus(TbTeacher tbTeacher) {
        tbTeacherMapper.updatestatus(tbTeacher);
    }
}
